import request from '@/utils/request';

export interface Supplier {
  supplierId: number;
  name: string | null;
  score: number | null;
  contactPerson: string | null;
  contactPhone: string | null;
}
export interface SupplierListResponse {
  current: number;
  total: number;
  pages: number;
  size: number;
  records: Supplier[];
}
export interface FormItemConfig {
  type: 'input' | 'datetime' | 'select';
  label: string;
  prop: keyof Supplier;
  placeholder?: string;
  inputType?: HTMLInputElement['type'];
  options?: Array<{label: string, value: any}>;
}

export interface SupplierModel {
  isUpdate: boolean | null;
  supplierId: number | null;
  name: string | null;
  score: number | null;
  contactPerson: string | null;
  contactPhone: string | null;
}

export const supplierApi = {
  getSupplierList: (params: any) => {
    return request<SupplierListResponse>({
      method: 'GET',
      url: `/procedure/suppliers`,
      params: params
    });
  },

  addSupplier: (data: SupplierModel) => {
    return request<String>({
      method: 'POST',
      url: `/procedure/suppliers`,
      data: data
    });
  },

  updateSupplier: (id: number, data: SupplierModel) => {
    return request<String>({
      method: 'PUT',
      url: `/procedure/suppliers/${id}`,
      data: data
    });
  },

  deleteSupplier: (id: number) => {
    return request<String>({
      method: 'DELETE',
      url: `/procedure/suppliers/${id}`,
    });
  },
};
